//
//  growthMorePicDayVController.m
//  SKaURobot
//
//  Created by cdong on 16/3/4.
//  Copyright © 2016年 cdong. All rights reserved.
//

#import "growthMorePicDayVController.h"
#import "growthDetailVController.h"
#import "growthRightCVCell.h"

@interface growthMorePicDayVController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>

@property (nonatomic ,strong)UICollectionView *morePicDayCollectionV;

@property (nonatomic ,strong)NSString *loadedStr;
@property (nonatomic ,strong)NSString *totalStr;
@property (nonatomic ,strong)UIButton *selectBtn;
@property (nonatomic ,strong)UIButton *backBtn;
@property (nonatomic ,strong)UILabel *navigationVL;
@property (nonatomic ,strong)UILabel *navigationUnderVL;
@property (nonatomic ,strong)UIView *navigationV;
@property (nonatomic ,strong)UIImageView *photoV;
@property (nonatomic ,assign)BOOL selecedFlag;

@end

@implementation growthMorePicDayVController

- (UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}

- (void)backBtnAction:(UIButton *)sender{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
     self.navigationController.navigationBarHidden = YES;
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.selecedFlag = NO;
    [self loadNavigationBg];
    [self loadphotoCollectionView];
    
    [self.backBtn addTarget:self action:@selector(backBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.selectBtn addTarget:self action:@selector(selectBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.morePicDayCollectionV registerClass:[growthRightCVCell class] forCellWithReuseIdentifier:@"growthRightCVCell"];
    
    self.morePicDayCollectionV.delegate = self;
    self.morePicDayCollectionV.dataSource = self;
}

// 选择图片
- (void)selectBtnAction:(UIButton *)sender{
    self.selecedFlag = YES;
}

- (void)loadNavigationBg{
    self.navigationV = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 375*matchW, 64)];
    self.navigationV.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"top_bg"]];
    [self.view addSubview:self.navigationV];
    
    self.navigationVL = [[UILabel alloc]initWithFrame:CGRectMake(((self.view.frame.size.width - 140)/2), 31, 140, 18)];
    self.navigationVL.text = @"2015年12月15日";
    self.navigationVL.textAlignment = NSTextAlignmentCenter;
    self.navigationVL.textColor = [RGBColorEncapsulation colorWithRGB:0xffffff alpha:1];
    self.navigationVL.font = [UIFont systemFontOfSize:18];
    [self.navigationV addSubview:self.navigationVL];
    
    self.navigationUnderVL = [[UILabel alloc]initWithFrame:CGRectMake(((self.view.frame.size.width - 140)/2), CGRectGetMaxY(self.navigationVL.frame), 140, 15)];
    NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:@"已加载30张／共120张"];
    [AttributedStr addAttribute:NSForegroundColorAttributeName
                          value:[RGBColorEncapsulation colorWithRGB:0xb81818 alpha:1]
                          range:NSMakeRange(0, 6)];
    
    [AttributedStr addAttribute:NSForegroundColorAttributeName
                          value:[RGBColorEncapsulation colorWithRGB:0xffffff alpha:1]
                          range:NSMakeRange(6, AttributedStr.length-6)];
    self.navigationUnderVL.attributedText = AttributedStr;
    self.navigationUnderVL.textAlignment = NSTextAlignmentCenter;
    self.navigationUnderVL.font = [UIFont systemFontOfSize:10];
    [self.navigationV addSubview:self.navigationUnderVL];
    
    self.backBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.backBtn.frame = CGRectMake(12*matchW, CGRectGetMinY(self.navigationVL.frame) + 2, 30, 30);
    [self.backBtn setBackgroundImage:[UIImage imageNamed:@"2left"] forState:UIControlStateNormal];
    [self.navigationV addSubview:self.backBtn];
    
    self.selectBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.selectBtn.frame = CGRectMake(self.view.frame.size.width - 40 - 12*matchW, CGRectGetMinY(self.backBtn.frame), 40, 30);
    [self.selectBtn setTitle:@"选择" forState:UIControlStateNormal];
    self.selectBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [self.selectBtn setTitleColor:[RGBColorEncapsulation colorWithRGB:0xbab9ba alpha:1] forState:UIControlStateNormal];
    [self.navigationV addSubview:self.selectBtn];
}

- (void)loadphotoCollectionView{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.itemSize = CGSizeMake((self.view.frame.size.width - 4)/4, (self.view.frame.size.width - 4)/4);
    layout.minimumInteritemSpacing = 1;
    layout.minimumLineSpacing = 1;
//    layout.sectionInset = UIEdgeInsetsMake(20, 0, 20, 0);
//    layout.headerReferenceSize = CGSizeMake(self.view.frame.size.width, (20+31)*matchH);
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    self.morePicDayCollectionV = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 64 + 10*matchH , self.view.frame.size.width, self.view.frame.size.height - 64 - 10*matchH ) collectionViewLayout:layout];
    self.morePicDayCollectionV.bounces = NO;
    self.morePicDayCollectionV.showsHorizontalScrollIndicator = NO;
    self.morePicDayCollectionV.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.morePicDayCollectionV];
}

// 分组数
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}

// 每一组个数
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 17;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    growthRightCVCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"growthRightCVCell" forIndexPath:indexPath];
    cell.selected = NO;
    cell.imageV.image = [UIImage imageNamed:@"default_pic"];
    //    [cell.imageV sd_setImageWithURL:[NSURL URLWithString:@"wifi"] placeholderImage:[UIImage imageNamed:@"default_pic"] completed:nil];
    return cell;
}

// 照片详情
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if (self.selecedFlag) {
        // pic_chosen@2x
        UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];
        UIImageView *selectImageV = [UIImageView alloc]initWithFrame:CGRectMake(cell.frame.size.width - 26*matchW, 0, 21*matchW, <#CGFloat height#>);
    }else{
        growthDetailVController *detailVC = [[growthDetailVController alloc]init];
        [self.navigationController pushViewController:detailVC animated:YES];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
